// 重组数组
export function setArr(obj) {
  const newArr = []
  if (obj.length > 0) {
    obj.forEach((i) => {
      let addObj = {}
      if (i.children.length > 0) {
        addObj = {
          label: i.name,
          value: i.id,
          children: setArr(i.children)
        }
      } else {
        addObj = {
          label: i.name,
          value: i.id
        }
      }

      newArr.push(addObj)
    })
  }
  return newArr
}
//  重组表单组件的数据
export function getFormComponent(param, newArr = []) {
  const arr = []
  if (param.length > 0) {
    param.forEach((i, index) => {
      if (i.type === 'grid') {
        if (i.columns.length > 0) {
          i.columns.forEach(j => {
            getFormComponent(j.list, newArr)
          })
        }
      } else {
        arr.push({
          type: i.type,
          name: i.name,
          model: i.model,
          options: i.options
        })
      }
    })
    newArr.push.apply(newArr, arr)
    return newArr
  }
}
//  平铺数组
export function setJsonLists(param, newArr = []) {
  const arr = []
  if (param.length > 0) {
    param.forEach(i => {
      if (i.type === 'grid') {
        if (i.columns.length > 0) {
          i.columns.forEach(j => {
            setJsonLists(j.list, arr)
          })
        }
      } else {
        return arr.push(i)
      }
    })
    newArr.push.apply(newArr, arr)
    return newArr
  }
}
// 判断是否有显示上传附件单选按钮
export function isfileUpload(param) {
  if (param.length > 0) {
    return param.some(i => {
      return i.model === 'isFileUpload'
    })
  }
}